<table class="table table-bordered">
      <thead>
        <tr>
          <th>规格名称<span style="color:red;">(必填)</span></th>
          <th>成本价<span style="color:red;">(必填)</span></th>
          <th>销售价<span style="color:red;">(必填)</span></th>
          <th>销售价<span style="color:red;">(必填)</span></th>
          <th>销售价<span style="color:red;">(必填)</span></th>
          <!-- <th>重量（单位斤）</th> -->
          <!--<th>成本价格</th>-->
          <!-- <th>代理价格</th> -->
          <!--<th>打包价格</th>-->
          <th>市场价格<span style="color:red;">(必填)</span></th>
          <th>剩余库存</th>
          <th>限购(不限购：0)</th>
          <th></th>
        </tr>
      </thead>
      <tbody id="rulebox">

        {empty name="value"}
        <tr>
          <td><input type="text" name="rule_name[]" /></td>
          <td><input type="text" name="rule_price[]" /></td>
          <td><input type="text" name="rule_price2[]" /></td>
          <td><input type="text" name="rule_price3[]" /></td>
          <td><input type="text" name="rule_price4[]" /></td>
          <!-- <td><input type="text" name="weight[]" /></td> -->
          <!--<td><input type="text" name="cost_price[]" /></td>-->
          <!-- <td><input type="text" name="agent_price[]" /></td> -->
          <!--<td><input type="text" name="pack_price[]" /></td>-->
          <td><input type="text" name="market_price[]" /></td>
          <td><input type="text" name="stock[]" value='999' /></td>
          <td><input type="text" name="quota[]" value='0' /></td>
          <td><a href="javascript:void(0);" class="btn btn-success" data-dismiss="addrule" style="padding:5px;">添加规格</a></td>
        </tr>
        {else /}
          {volist name="value" id="vo"}
            <tr>
                <input type="hidden" name="rule_id[]" value="{$vo.id}"  />
            <td><input type="text" name="rule_name[]" value="{$vo.rule_name}" /></td>

            <td><input type="text" name="rule_price[]" value="{$vo.rule_price}" /></td>
              <td><input type="text" name="rule_price2[]"  value="{$vo.rule_price2}"/></td>
              <td><input type="text" name="rule_price3[]"  value="{$vo.rule_price3}"/></td>
              <td><input type="text" name="rule_price4[]"  value="{$vo.rule_price4}"/></td>
            <!-- <td><input type="text" name="weight[]" value="{$vo.weight}" /></td> -->
            <!--<td><input type="text" name="cost_price[]" value="{$vo.cost_price}" /></td>-->
            <!-- <td><input type="text" name="agent_price[]" value="{$vo.agent_price}" /></td> -->
            <!--<td><input type="text" name="pack_price[]" value="{$vo.pack_price}" /></td>-->
            <td><input type="text" name="market_price[]" value="{$vo.market_price}" /></td>
            <td><input type="text" name="stock[]" value="{$vo.stock}" /></td>
            <td><input type="text" name="quota[]" value="{$vo.quota}" /></td>
            <td>
              {eq name="i" value='1'}
                <a href="javascript:void(0);" class="btn btn-success" data-dismiss="addrule" style="padding:5px;">添加规格</a></td>
              {else/}
                <a href="javascript:void(0);" class="btn btn-danger" data-dismiss="removerule" style="padding:5px;">移除</a>
              {/eq}
            </tr>
          {/volist}
        {/empty}

      </tbody>
    </table>


    <script id="tpl" type="text/x-jquery-tmpl">
      <tr>
      <td><input type="text" name="rule_name[]" /></td>
          <td><input type="text" name="rule_price[]" /></td>
          <td><input type="text" name="rule_price2[]" /></td>
          <td><input type="text" name="rule_price3[]" /></td>
          <td><input type="text" name="rule_price4[]" /></td>
      <td><input type="text" name="market_price[]" /></td>

      <td><input type="text" name="stock[]" value='999' /></td>
      <td><input type="text" name="quota[]" value='0' /></td>
      <td><a href="javascript:void(0);" class="btn btn-danger" data-dismiss="removerule" style="padding:5px;">移除</a></td>
      </tr>
    </script>
    <script src="__PUBLIC__/js/jquery.tmpl.js" charset="utf-8"></script>
<script>
  $.template( 'tpl', $("#tpl"));
  $('[data-dismiss="addrule"]').click(function(){
    data = {'name':1};
    $.tmpl( 'tpl', data ).appendTo($("#rulebox"));
  })
  $(document).on('click', '[data-dismiss="removerule"]',function(){
    $(this).parents('tr').remove();
  })

  $('[name="rule_price[]"]').blur(function(){
  var $tr = $(this).parents('tr'),
      val1 = $(this).val();

      var val2= parseInt(val1)+0.5,
          val3 = parseInt(val1)+0.5,
          val4 = parseInt(val1)+0.5;
          val5 = val1*1.5;
  $tr.find('[name="rule_price2[]"]').val(val2.toFixed(1))
  $tr.find('[name="rule_price3[]"]').val(val3.toFixed(1))
  $tr.find('[name="rule_price4[]"]').val(val4.toFixed(1))
  $tr.find('[name="market_price[]"]').val(val5.toFixed(1))

  });

</script>
